const jwt=require("jwt-simple");
const express=require("express");
let router=express.Router();
router.use((request,response,next)=>{
    if(request.body.token || request.query.token || request.headers.token){
       
        try {
            let token=request.body.token || request.query.token || request.headers.token;
            let result=jwt.decode(token,require("../config").tokenKey);
            if(result){
                request.Info=result.info;
                next();
            }
        } catch (error) {
                response.json({
                    code:200,
                    msg:"token失效,请重新登录~~~",
                    error
                })
        }
    }
})

router.get("/getCart", require("../controller/carts").getCart);
router.post("/deleteCart", require("../controller/carts").deleteCart);
router.post("/updataCart", require("../controller/carts").updataCart);
router.post("/addCart", require("../controller/carts").addCart);
router.get("/giveMoney", require("../controller/carts").giveMoney);

module.exports=router;